package com.itheima.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

//@WebFilter(urlPatterns = "/*")  //设置拦截路径
//@WebFilter(value = "/*")
//@WebFilter("/*")
public class DemoFilter implements Filter {
    //初始化方法
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("初始化方法执行了...");
    }

    //每次请求被拦截时执行
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("doFilter方法执行了...");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    //销毁方法
    @Override
    public void destroy() {
        System.out.println("销毁方法执行了...");
    }
}
